package CH01_05;

/**
 * Created by lenovo on 2016/3/20.
 */
class Clothes {
    String color;
    char size;
    Clothes(String color, char size) {
        this.color = color;
        this.size = size;
    }
}

public class Copy {
    public static void main(String[] args) {
        Clothes[] c1 = {new Clothes("red", 'L'), new Clothes("blue", 'M')};
        Clothes[] c2 = new Clothes[c1.length];
        for(int i = 0; i < c1.length; i++) {
            c2[i] = c1[i];
        }
        c1[0].color = "yellow";
        System.out.println(c2[0].color);    //浅层复制的结果

        Clothes[] c3 = {new Clothes("red", 'L'), new Clothes("blue", 'M')};
        Clothes[] c4 = new Clothes[c3.length];
        for(int i = 0; i < c3.length; i++) {
            Clothes c = new Clothes(c3[i].color, c3[i].size);
            c4[i] = c;
        }
        c3[0].color = "yellow";
        System.out.println(c4[0].color);    //深层复制的结果
    }
}
